#ifndef _GLOBAL_DEF_H
#define _GLOBAL_DEF_H
#include <string>

#define MAX_TABLE_NUM 0x1000
#define MAX_COLUMN_NUM 0x1000
#define TABLE_NUM_START 0x1001
#define MAX_NAME_HASH   (MAX_TABLE_NUM+MAX_COLUMN_NUM)
//#define BL_CONV(x)  __builtin_bswap32(x) 
#define BL_CONV(x) (x)
enum DataType
{
  INTEGER,
  VARCHAR,
  UNKNOWN_TYPE
};

typedef unsigned int OBJID;
typedef unsigned short OFFSET;
typedef unsigned char _byte;

enum CondType
{
  CT_CONST_STRING = 0,
  CT_CONST_INT = 1,
  CT_LESS = 2,
  CT_GREATER = 3,
  CT_JOIN = 4,
  CT_RANGE = 5,
  CT_UNKNOWN
};
struct CondInfo
{
  CondType type;
  OBJID op1_table;		//index of table
  OBJID op1;			//index of column
  OBJID op2_table;
  OBJID op2;			//index of column
  std::string str_op2;		//string constant
  int int_op2;
  std::pair<int,int> range;
  CondInfo():type(CT_UNKNOWN),op1_table(0),op1(0),op2_table(0),op2(0),int_op2(0){}
};

inline bool less_cond(const CondInfo &ci1, const CondInfo &ci2){
  bool b1 = (ci1.type==CT_LESS)||(ci1.type==CT_GREATER);
  bool b2 = (ci2.type==CT_LESS)||(ci2.type==CT_GREATER);
  return (!b1)&&b2;
}

//bool cmpPredicate_slow(const CondInfo &ci1, const CondInfo &ci2);

template<typename T> class IndexDb;
typedef IndexDb<std::string> IndexDbS;
typedef IndexDb<int>    IndexDbI;


class MyDb;

extern MyDb *id2db[MAX_NAME_HASH];

#endif
